﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Johnny.Helper {
    public static class StringHelper {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <param name="length">length = 0: get all string</param>
        /// <returns></returns>
        public static string RemoveHTMLTag (string input, int? length) {
            if (input == null)
                return String.Empty;
            string output = System.Text.RegularExpressions.Regex.Replace(HttpUtility.HtmlDecode(input), "<(.|\n)*?>", string.Empty);
            output = System.Text.RegularExpressions.Regex.Replace(HttpUtility.HtmlDecode(output), "<(.|\n)*?>", string.Empty).Trim().Replace("&nbsp;", "");
            int get = (length.HasValue) ? ((output.Length < length.Value) ? output.Length : length.Value) : output.Length;
            output = output.Substring(0, get);
            return output;
        }
    }
}